<include file="Layout/header" />
<body>
<div class="breadcrumbs" id="breadcrumbs"> 
  <script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
  <ul class="breadcrumb">
    <li> <i class="icon-home home-icon"></i> <a href="{:U('Admin/Index/welcome')}">首页</a> </li>
    <li class="active">地区管理</li>
  </ul>
</div>
<div class="page-content">
  <div class="page-header">
    <h1> 地区管理 <small> <i class="icon-double-angle-right"></i> 地区管理 </small> </h1>
  </div>
  <div class="row">
    <div class="col-xs-12"> <a class="btn btn-primary" href="{:U('Admin/Region/region_add')}"><i class="icon-pencil align-top bigger-125"></i>新增地区</a>
      <div class="table-responsive">
        <table id="example-advanced" class="table table-striped table-bordered table-hover">
          <thead>
            <tr>
              <!-- <th class="center"> <label>
                  <input class="ace" type="checkbox">
                  <span class="lbl"></span> </label>
              </th> -->
              <th>分类名称</th>
              <th>地区</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
           
          <form method="post" action="{:U('Admin/Region/region_del')}" id="ondel">
            <foreach name="region" item="val">
              <tr>
                <!-- <td class="center"><label>
                    <input class="ace" type="checkbox" value="{$val.id}" name="id[]">
                    <span class="lbl"></span> </label></td> -->
                <td class="hidden-480">
                 
                <div class="col-sm-8">
                <i class="icon-plus" style="float: left;padding: 6px;" onClick="get_region(this,{$val.id})"></i>
                     <input id="n_{$val.id}" class="col-xs-10 col-sm-8" type="text" value="{$val.name}" onBlur="onblus_name({$val.id})">
                  </div>
                   
                  </td>
                 <td>{$val.region}</td>
                <td><div class="visible-md visible-lg hidden-sm hidden-xs btn-group"> <a class="btn btn-xs btn-info" href="{:U('Admin/Region/region_edit')}/id/{$val.id}"> <i class="icon-edit bigger-120"></i> </a> <a class="btn btn-xs btn-danger" onClick="region_del(this,{$val.id})"> <i class="icon-trash bigger-120"></i> </a> </div></td>
              </tr>
             </foreach>
          </form>
            </tbody>
          
        </table>
        <!-- <div>
          <button class="btn btn-danger" onClick="datadel()">批量删除</button>
        </div> -->
      </div>
      
      <!-- /.table-responsive --> 
    </div>
      <input type="hidden" value="{:U('Admin/Region/get_region')}" id="get_region">
      <input type="hidden" value="{:U('Admin/Region/edit_name')}" id="edit_name">
      <input type="hidden" value="{:U('Admin/Region/region_del')}" id="region_del">
  </div>
</div>
<include file="Layout/js"/>
<link rel="stylesheet" href="__ADMIN_CSS__/jquery.treetable.css" />
<script src="__ADMIN_JS__/jquery.dataTables.min.js"></script> 
<script src="__ADMIN_JS__/jquery.dataTables.bootstrap.js"></script> 
<script src="__ADMIN_JS__/bootbox.js"></script> 
<script type="text/javascript">
			jQuery(function($) {
 													   
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
			
  				
			})
 		</script> 
<script type="text/javascript">       
 
function onblus_name(id){
    var id=id;
	var name=$("#n_"+id+"").val()
	var host=$("#edit_name").val(); 
	//var host='/index.php/Admin/Region/edit_name';
    $.post(host,{id :id,name:name},function (data){
		 if(data.status==0){
 		bootbox.alert(data.info);	
		 }
 	   });
	 
}
     /* 删除*/
function region_del(obj,id){
	var host=$("#region_del").val();
      bootbox.setLocale("zh_CN");  
      bootbox.confirm("确定删除该地区?", function(result) {  
        if (result) {  
           $.ajax({
			 url:host,
			type:"POST",
			dataType:"json",
			data:{id:id},
			success: function(data){
 				if(data.status==0){
 				bootbox.alert(data.info);	
					}else{
				$(obj).parents("tr").remove();		
						}
				}
			})
		
		 
        }  
      });  
 
}
/*批量-删除*/
function datadel(){
	
	 bootbox.setLocale("zh_CN");  
      bootbox.confirm("确定删除该分类?", function(result) {  
        if (result) {  
           $("#ondel").submit();
         }  
      });  
	 
	
}
function get_region(obj,id){
	var statu= $(obj).attr('class');
	 //var url='/index.php/admin/region/get_region/'
	 var url=$("#get_region").val();
	 if(statu=='icon-plus'){
	 $(obj).addClass("icon-minus");
 	 $(obj).removeClass("icon-plus");
	 $.ajax({
				url: url,
				dataType: 'json',
				data:{pid:id},
				success: function(data){
   					var src='';
					for(var i = 0; i < data.region.length; i++){
 						src += "<tr data='"+data.region[i].pid+"'>";
						//src += "<td class='center'><label><input type='checkbox' name='id[]' value='"+data.region[i].id+"' class='ace'><span class='lbl'></span></label></td>";
						if(data.region[i].deep=='2'){
						src += "<td class='hidden-480' style='padding-left:40px'><i class='icon-plus' style='float: left;padding: 6px;' onClick='get_region(this,"+data.region[i].id+")'></i>";
						}else{
						src += "<td class='hidden-480' style='padding-left:80px'>";	
							}
						src += "<input type='text' name='n_"+data.region[i].id+"' value='"+data.region[i].name+"' class='col-xs-10 col-sm-5'  onBlur='onblus_name("+data.region[i].id+")'></td>";
						src +="<td> </td>";
						src += "<td><div class='visible-md visible-lg hidden-sm hidden-xs btn-group'><a class='btn btn-xs btn-info' href='{:U('Admin/Region/region_edit')}/id/"+data.region[i].id+"'> <i class='icon-edit bigger-120'></i> </a> <a class='btn btn-xs btn-danger' onClick='region_del(this,"+data.region[i].id+")'> <i class='icon-trash bigger-120'></i> </a> </div></td>";
						}
					var pr = $(obj).parents("tr");
					pr.after(src);	
				}
	 });
	}else{
	 $(obj).removeClass("icon-minus");
 	 $(obj).addClass("icon-plus");	
	  $.ajax({
				url: url,
				dataType: 'json',
				data:{pid:id},
				success: function(data){
					if(data.flag==1)
					{
					 $("tr[data="+id+"]").remove();	
				 		}else{
 					      for(var i = 0; i < data.region.length; i++){
 						  $("tr[data="+data.region[i].id+"]").remove(); 
						  }
						  $("tr[data="+id+"]").remove();		
							}
				}
	  });
	
	}
 
	}
 </script>
 
</body>
</html>